package main

import (
	"context"
	pb "demo/micro/grpc/proto"
	"fmt"
	"google.golang.org/grpc"
)

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

func StartClient() {
	conn, err := grpc.Dial(":8972", grpc.WithInsecure())
	checkErr(err)
	defer conn.Close()

	c := pb.NewGreeterClient(conn)
	resp, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: "林芳伊"})
	checkErr(err)

	fmt.Println(resp.Message)

	c1 := pb.NewLinfangyiServiceClient(conn)
	resp1, err := c1.Hello(context.Background(), &pb.LinfangyiRequest{Question: "name"})
	checkErr(err)
	fmt.Println(resp1.Resp)

	resp1, err = c1.Hello(context.Background(), &pb.LinfangyiRequest{Question: "age"})
	checkErr(err)
	fmt.Println(resp1.Resp)
}
